package com.xxd.rpt2.config

import com.xxd.rpt2.Entity.User
import com.xxd.utils.JwtUtil
import org.apache.shiro.authc.AuthenticationInfo
import org.apache.shiro.authc.AuthenticationToken
import org.apache.shiro.authc.credential.CredentialsMatcher

class JwtCredentialsMatcher implements CredentialsMatcher{
    @Override
    boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        String jwtToken = (String) token
        String salt = (String)info.getCredentials()
        User user = (User)info.getPrincipals().getPrimaryPrincipal()
        return JwtUtil.verify(jwtToken,user.getCode(),salt)
    }
}
